package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Liangyaoyun
 */
public class leetCode94 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<Integer>();
        middleOrderTraversal(res, root);
        return res;
    }

    public void middleOrderTraversal(List<Integer> res, TreeNode root) {
        if (root == null) {
            return;
        }
        middleOrderTraversal(res, root.left);
        //因为另外一个方法中有返回值，所以打印这一步换成添加
        res.add(root.val);
        middleOrderTraversal(res, root.right);
    }
}
